//
//  WPRegisterAndForgetView.m
//  wobingwoyi
//
//  Created by WGP on 16/7/29.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPRegisterAndForgetView.h"

@interface WPRegisterAndForgetView ()

@property(nonatomic,copy)void(^handleBlock)(WPLoginViewType type);
@property(nonatomic,strong)WPBtnNoHighLight *registerBtn;
@property(nonatomic,strong)WPBtnNoHighLight *forgetBtn;

@end
@implementation WPRegisterAndForgetView

+(instancetype)registerAndForgetPwdViewWith:(void(^)(WPLoginViewType type))handleBlock
{
    return [[self alloc] initWithHandleBlock:handleBlock];
}

-(instancetype)initWithHandleBlock:(void(^)(WPLoginViewType type))handleBlock
{
    if (self = [super init]) {
        
        self.handleBlock = handleBlock;
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
//    self.backgroundColor = [UIColor orangeColor];
    
    WPBtnNoHighLight *registerBtn = [WPBtnNoHighLight buttonWithType:UIButtonTypeCustom];
    UIView *lineView = [UIView new];
    WPBtnNoHighLight *forgetPwdBtn = [WPBtnNoHighLight buttonWithType:UIButtonTypeCustom];
    
    self.registerBtn = registerBtn;
//    self.registerBtn.titleLabel.backgroundColor = [UIColor orangeColor];
    self.forgetBtn = registerBtn;
    
    [registerBtn setTitle:@"注册账号" forState:UIControlStateNormal];
    [forgetPwdBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
    
    [registerBtn setTitleColor:GlobalColor forState:UIControlStateNormal];
    [forgetPwdBtn setTitleColor:RGB_SAME(153) forState:UIControlStateNormal];
    
    registerBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    forgetPwdBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [registerBtn.titleLabel sizeToFit];
    [forgetPwdBtn.titleLabel sizeToFit];
    
    
    [registerBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchDown];
    [forgetPwdBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchDown];
    
    lineView.backgroundColor = GLobalLineColor;
    
    
    [self addSubview:registerBtn];
    [self addSubview:lineView];
    [self addSubview:forgetPwdBtn];
    
    [registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self);
        make.right.equalTo(self.mas_centerX).offset(-16*KWIDTH_SCALE);
    }];
    
    [forgetPwdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(registerBtn.mas_right).offset(32*KWIDTH_SCALE);
        make.centerY.equalTo(self);
    }];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(0.5);
        make.centerX.equalTo(self);
        make.top.bottom.equalTo(registerBtn.titleLabel);
    }];
}

-(void)btnDidClick:(WPBtnNoHighLight *)btn
{
    if (self.handleBlock) {
        if (btn == self.registerBtn) {
            
            self.handleBlock(WPLoginViewTypeRegister);
            
        }else
        {
            self.handleBlock(WPLoginViewTypeForgetPwd);
        }
    }
}

@end











